package com.zxl.util;

import java.util.ArrayList;
import java.util.Date;

import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SchedulerFactory;
import org.quartz.Trigger;
import org.quartz.TriggerUtils;
import org.quartz.impl.StdSchedulerFactory;

public class TimerTest {

	public static void main(String... strings) {
		SchedulerFactory schedFact = new org.quartz.impl.StdSchedulerFactory();

		Scheduler sched;
		try {

			// sched = schedFact.getScheduler();
			sched = StdSchedulerFactory.getDefaultScheduler();

			JobDetail jobDetail = new JobDetail("myJob", // job name
					sched.DEFAULT_GROUP, // job group (you can also specify
											// 'null' to
					// use the default group)
					TestJob.class); // the java class to execute

			jobDetail.getJobDataMap().put("jobSays", "Hello World!");
			jobDetail.getJobDataMap().put("myFloatValue", 3.141f);
			jobDetail.getJobDataMap().put("myStateData", new ArrayList());

		    Trigger trigger = TriggerUtils.makeSecondlyTrigger(3); //3秒执行一次
			trigger.setStartTime(new Date());
			trigger.setName("myTrigger");

			// Add the given JobDetail to the Scheduler,
			// and associate the given Trigger with it.
			sched.scheduleJob(jobDetail, trigger);
			sched.start();
			//sched.shutdown();

		} catch (SchedulerException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}